package com.yaoxun.console.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yaoxun.console.code.BaseResponseCode;
import com.yaoxun.console.service.LogoutService;
import com.yaoxun.console.service.UserService;
import com.yaoxun.console.xo.req.PasswrodUpdateReq;
import com.yaoxun.console.xo.resp.ApiResp;
import com.yaoxun.console.xo.resp.BooResp;

@Controller
public class IndexController implements BaseController {

	@Autowired
	private LogoutService logoutService;
	
	@Autowired
	private UserService userService;
	
	
	@GetMapping(value = {"", "/"})
	public String index() {
		return "redirect:/page/index.html";
	}
	
	
	@ResponseBody
	@PostMapping("/logout")
	public ApiResp<BooResp> logout() {
		logoutService.logout();
		return ofRoSuccess(BooResp.of(true));
	}
	
	@ResponseBody
	@PostMapping("/password/update")
	public ApiResp<BooResp> updatePassword(@RequestBody PasswrodUpdateReq req){
		userService.updatePassword(req);
		return ofRo(BaseResponseCode.UPDATE_SUCCESS, BooResp.of(true));
	}
	
}
